export default (position1, position2, unit) => {
	let lat1 = position1.latitude;
	let lng1 = position1.longitude;
	let lat2 = position2.latitude;
	let lng2 = position2.longitude;
	let radLat1 = lat1 * Math.PI / 180.0;
	let radLat2 = lat2 * Math.PI / 180.0;
	let a = radLat1 - radLat2;
	let b = lng1 * Math.PI / 180.0 - lng2 * Math.PI / 180.0;
	let s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) +
		Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(b / 2), 2)));
	s = s * 6378.137; // EARTH_RADIUS;
	s = Math.round(s * 10000) / 10;
	if (unit) {
		return s + unit;
	} else {
		if (s >= 1000) {
			return (s / 1000).toFixed(2) + 'km';
		} else {
			return s + 'm';
		}
	}
}
